<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 加载资源时候不添加当前地址得引用信息 这样可以解决部分得网页安全认证 -->
    <meta name="referrer" content="never">
    <link rel="stylesheet" href="/admin/css/bootstrap.min.css">
    <link href="/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="/admin/css/animate.css" rel="stylesheet">
    <link href="/admin/css/style.css?v=4.1.0" rel="stylesheet">

    <title>列表页</title>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>影片管理</h5>
            </div>

            <div class="ibox-content">
                <a href="/admin/movies/new" class="btn btn-primary btn-sm">新增 </a>

                <table class="table table-hover table-bordered">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>名字</th>
                            <th>主图</th>
                            <th>浏览次数</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <%list.forEach((item,index)=>{%>
                        <tr>
                            <td><%=index+1%></td>
                            <td><%=item.name%></td>
                            <td><img style="max-width:120px;max-height:150px;" src="<%= item.img %>" /></td>
                            <td><%=item.views%></td>
                            <td>
                                <a href="/admin/movies/edit/<%=item.id%>" class="btn btn-primary btn-sm">修改</a>
                                <a href="javascript:void(0)" onclick="delOne('<%=item.id%>')"
                                    class="btn btn-danger btn-sm">删除</a>

                            </td>
                        </tr>
                        <%})%>
                    </tbody>
                </table>
                <div id="Paginator" style="text-align: center">
                    <ul id="pageLimit"></ul>
                </div>
            </div>

        </div>
    </div>
    <form action="/admin/movies/del" id="delForm" method="POST">

        <input type="hidden" name="id" id="delId">
    </form>
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/admin/js/bootstrap-paginator.min.js">

    </script>
    <script>
        //投机取巧
        function delOne(id) {
            if (confirm('是否确定删除此项'))
                //删除我要穿得id
                document.getElementById('delId').value = id;
            document.getElementById('delForm').submit();
        }
        $("#pageLimit").bootstrapPaginator({
            currentPage: <%= page%>, // 当前页码
            totalPages: <%=pages%>, // 总页数
            size: "normal",
            bootstrapMajorVersion:3,
            alignment: "right",
            numberOfPages: 5,
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "末页";
                    case "page":
                        return page;
                }
            },
            onPageClicked: function (e, oe, t, p) {
                // console.log(e);
                // console.log(oe);
                // console.log(t);
                // console.log(p);
                window.location.href = "/admin/movies?page=" + p;
            },
        });
    </script>
</body>

</html>